﻿package mortal.game.view.monthInvestment
{
    import Message.DB.Tables.*;
    import Message.Public.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import extend.language.*;
    import fl.data.*;
    import flash.events.*;
    import mortal.component.ui.*;
    import mortal.component.window.*;
    import mortal.game.cache.*;
    import mortal.game.resource.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.monthInvestment.view.*;
    import mortal.mvc.interfaces.*;

    public class MonthInvestmentModule extends BaseWindow
    {
        private var _tabBar:GTileList;
        private var _currentPanel:GSprite;
        private var _consumeBox:GConsumeBox;
        private var _consumeBox2:GConsumeBox;
        private var _rechargeBtn:GLoadingButton;

        public function MonthInvestmentModule(param1:ILayer = null)
        {
            super(param1);
            this.setSize(883, 586);
            this.title = Language.getString(35410);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this.pushUIToDisposeVec(UIFactory.bg(7, 34, 190, 539, this, ImagesConst.PanelBg));
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.MonthInvestTxt1, 15, 500, this));
            this._tabBar = UIFactory.tileList(7, 38, 188, 500, this);
            this._tabBar.rowHeight = 58;
            this._tabBar.columnWidth = 188;
            this._tabBar.horizontalGap = 5;
            this._tabBar.verticalGap = 5;
            this._tabBar.setStyle("cellRenderer", MonthInvestTabCellRender);
            this._tabBar.configEventListener(Event.CHANGE, this.tabBarChangeHandler);
            this._consumeBox = UIFactory.gConsumeBox("", 98 + 168, 145, 0, this.contentTopOf3DSprite);
            this._consumeBox.addItem(ConsumeData.ShowMoneyType, EPriceUnit._EPriceUnitGold, 0, Language.getString(35411));
            this._consumeBox2 = UIFactory.gConsumeBox("", 240 + 168, 145, 0, this.contentTopOf3DSprite);
            this._consumeBox2.addItem(ConsumeData.ShowMoneyType, EPriceUnit._EPriceUnitGoldBind, 0, Language.getString(35412));
            this._rechargeBtn = UIFactory.gLoadingButton(ResFileConst.lotteryDrawRechargeBtn, 405 + 168, -21 + 160, 82, 29, this.contentTopOf3DSprite);
            this._rechargeBtn.configEventListener(MouseEvent.CLICK, this.gotoRecharge);
            this.updateTab();
            this._tabBar.selectedIndex = 0;
            this.tabBarChangeHandler();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._consumeBox.dispose(param1);
            this._consumeBox = null;
            this._consumeBox2.dispose(param1);
            this._consumeBox2 = null;
            this._tabBar.dispose(param1);
            this._tabBar = null;
            if (this._currentPanel)
            {
                this._currentPanel.dispose();
                this._currentPanel = null;
            }
            super.disposeImpl(param1);
            return;
        }// end function

        private function gotoRecharge(event:MouseEvent) : void
        {
            GameUtil.gotoRecharge(ModuleTypeConst.MonthInvestment);
            return;
        }// end function

        private function tabBarChangeHandler(event:Event = null) : void
        {
            var _loc_2:Object = null;
            if (this._currentPanel)
            {
                this._currentPanel.dispose();
                this._currentPanel = null;
            }
            if (this._tabBar.selectedIndex == 0)
            {
                this._currentPanel = this.addMonthInvestMainPanel();
                (this._currentPanel as MonthInvestMainPanel).updateInvestState();
            }
            else
            {
                this._currentPanel = this.addMonthInvestGetPanel();
                _loc_2 = this._tabBar.dataProvider.getItemAt(this._tabBar.selectedIndex);
                (this._currentPanel as MonthInvestGetPanel).updateInvestGetState(_loc_2.type, true);
            }
            this.addChild(this._currentPanel);
            return;
        }// end function

        private function addMonthInvestMainPanel() : MonthInvestMainPanel
        {
            var _loc_1:MonthInvestMainPanel = null;
            _loc_1 = UICompomentPool.getUICompoment(MonthInvestMainPanel);
            _loc_1.x = 168;
            _loc_1.y = 160;
            return _loc_1;
        }// end function

        private function addMonthInvestGetPanel() : MonthInvestGetPanel
        {
            var _loc_1:* = UICompomentPool.getUICompoment(MonthInvestGetPanel);
            _loc_1.x = 168;
            _loc_1.y = 160;
            return _loc_1;
        }// end function

        private function getDateProvider() : DataProvider
        {
            var _loc_4:TInvestBase = null;
            var _loc_6:Object = null;
            var _loc_7:int = 0;
            var _loc_1:* = new DataProvider();
            var _loc_2:* = MonthInvestmentConfig.instance.rewardArr;
            var _loc_3:* = _loc_2.length;
            var _loc_5:* = Cache.instance.role.entityInfo.level;
            _loc_6 = {type:0};
            _loc_1.addItem(_loc_6);
            while (_loc_7 < _loc_3)
            {
                
                _loc_4 = MonthInvestmentConfig.instance.getInvestBaseByType(_loc_7);
                if (_loc_4 && _loc_5 >= _loc_4.level)
                {
                    _loc_6 = {type:_loc_7};
                    _loc_1.addItem(_loc_6);
                }
                _loc_7++;
            }
            return _loc_1;
        }// end function

        public function updateTab() : void
        {
            this._tabBar.dataProvider = this.getDateProvider();
            return;
        }// end function

        public function updateInvestMent() : void
        {
            var _loc_1:Object = null;
            if (this._currentPanel is MonthInvestMainPanel)
            {
                (this._currentPanel as MonthInvestMainPanel).updateInvestState();
            }
            else if (this._currentPanel is MonthInvestGetPanel)
            {
                _loc_1 = this._tabBar.dataProvider.getItemAt(this._tabBar.selectedIndex);
                (this._currentPanel as MonthInvestGetPanel).updateInvestGetState(_loc_1.type);
            }
            return;
        }// end function

    }
}
